<?php
/**
 * Created by PhpStorm.
 * User: maqun
 * Date: 2016/2/29
 * Time: 14:49
 */
class PurviewAction extends BaseAction{

    public function _initialize(){
        self::$action = 4;
        parent::_initialize();
    }

    /**
     * 权限列表
     */
    public function index(){

        $list = D('Purview')->getPurviewList();
//        dump($list);exit;
        $this->assign('list',$list);

        $this->display('index');
    }

    /**
     * 添加权限
     */
    public function add(){

        $this->display('add');
    }

    /**
     * 编辑权限
     */
    public function edit(){

        $purview_id   = intval($this->_get('id'));
        $purview_info = D('Purview')->where('purview_id='.$purview_id)->select();

        if(empty($purview_info)){
            $this->error('数据不存在');
        }
        $this->assign('info',$purview_info[0]);
        $this->display('edit');
    }

    /**
     * 删除权限
     */
    public function delete(){
        $purview_id   = intval($this->_get('id'));
        $purview_info = D('Purview')->where('purview_id='.$purview_id)->select();
        if(empty($purview_info)){
            $this->error('数据不存在');
        }
        $res = D('Purview')->deletePurview();

        if($res['status']){
            $this->success($res['info'],U('/Purview/index'));
        }else{
            $this->error($res['info']);
        }
    }
    /**
     * 添加或修改保存数据
     */
    public function save(){

        $post = $this->_post();

        if(!empty($post)){
            $res = empty($post['id']) ? D('Purview')->addPurview($post) : D('Purview')->editPurview($post);
            if($res['status']){
                $this->success($res['info'],U('/Purview/index'));
            }else{
                $this->error($res['info']);
            }
        }
    }
}